<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>滑块组件 slider - Layui 文档</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script>;!function(){self!==parent&&(location.href="about:blank")}();</script>
  <link href="/public/layui/v/2.8.6/css/layui.css" rel="stylesheet">
  <link href="/public/static/dist/docs/2.8/css/global.css?v=16" rel="stylesheet">
  <script>
  (function(){if(window.JSON&&window.JSON.parse){var c=document.getElementsByTagName("head"),a=document.createElement("link");try{var b=JSON.parse(localStorage.layui)}catch(d){b={}}"dark"===b.themeMode&&(a.href="//res.sentcss.com/static/dist/docs/2.8/css/layui-theme-dark.css?v=16",a.rel="stylesheet",a.id="layuicss-theme-dark",c[0].appendChild(a))}})();
  </script>
</head>
<body>
<div class="layui-header ws-header ws-bg-light">
  <div class="layui-container">
    <div class="ws-logo">
      <a class="logo" href="../../../index.html">
        <img src="/public/static/images/layui/logo.png" alt="layui">
      </a>
    </div>
    <div class="ws-header-assist">
      <div class="layui-form layui-hide-xs ws-search" lay-filter="LAY-ws-header-component"></div>
      <div class="layui-hide-xs ws-notice"></div>
    </div>
    
    <div class="ws-header-menu">
      <ul class="layui-nav layui-bg-gray ws-bg-light" id="LAY_NAV_TOP">
        <li class="layui-nav-item" data-dir="docs">
          <a href="../index.html">组件</a> 
        </li>
        <li class="layui-nav-item" data-dir="notes">
          <a href="../../../notes/index.html">笔记</a> 
        </li>
        <li class="layui-nav-item layui-hide-xs">
          <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">
            <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>--> 
            生态
          </a>
          <dl class="layui-nav-child layui-nav-child-r" style="margin-right: -21px;">  
            <dd class="layui-hide-sm layui-show-xs" lay-unselect>
              <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
              <hr>
            </dd>
            <dd lay-unselect>
              <a href="https://dev.layuion.com/extend/" target="_blank">Layui 第三方扩展组件</a>
            </dd>
            <dd lay-unselect>
              <a href="https://github.com/Sight-wcg/layui-theme-dark" target="_blank" lay-unselect>
                Layui 深色主题 <span>(社区贡献)</span>
              </a>
            </dd>
            <dd lay-unselect>
              <a href="https://gitee.com/layui/layui-vue/" target="_blank" lay-unselect>
                Layui of Vue <span>(他人实现)</span>
              </a>
            </dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">2.8.6</a>
          <dl class="layui-nav-child layui-nav-child-c">  
            <dd lay-unselect class="layui-this"><a href="../../../index.html">2.8.6</a></dd>
            <dd lay-unselect><a href="../../../2.7/index.html">2.7.6</a></dd>
          </dl>
        </li>
      </ul>
      <div class="ws-header-more">
        <i class="layui-icon layui-icon-shrink-right"></i>
      </div>
      <div class="ws-header-tool ws-bg-light">
        <div class="layui-form ws-header-theme" lay-filter="header-theme">
          <input type="checkbox" name="theme-mode" id="ID-header-theme-mode" lay-filter="header-theme-mode" lay-skin="switch">
          <div lay-checkbox>
            <i class="layui-icon layui-icon-moon"></i> | 
            <i class="layui-icon layui-icon-light"></i>
          </div>
        </div>
        <div>
          <a href="https://github.com/layui/layui" target="_blank" title="Github">
            <i class="layui-icon layui-icon-github layui-font-20"></i>
          </a>
        </div>
        <div>
          <a href="https://gitee.com/layui/layui" target="_blank" title="Gitee">
            <i class="layui-icon layui-icon-gitee layui-font-20" style="color: #C71D23;"></i>
            <!--<img src="https://gitee.com/static/images/logo-en.svg" width="21">-->
          </a>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 让 IE8/9 兼容响应式栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
 
<div class="layui-container ws-container">
  
<div class="layui-panel ws-menu">
  <ul class="layui-menu layui-menu-lg ws-docs-menu">
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">基础</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../index.html">
              <span>开始使用</span> 
              <span class="layui-font-12 layui-font-gray">Getting Started</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../base.html">
              <span>底层方法</span>
              <span class="layui-font-12 layui-font-gray">Base Function</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../modules.html">
              <span>模块系统</span>
              <span class="layui-font-12 layui-font-gray">Modules</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../versions.html">
              <span>更新日志</span>
              <span class="layui-font-12 layui-font-gray">Versions</span>
              <span class="layui-badge-dot"></span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">布局</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layout/index.html">
              <span>框体</span>
              <span class="layui-font-12 layui-font-gray">Layout</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layout/grid.html">
              <span>栅格</span>
              <span class="layui-font-12 layui-font-gray">Grid</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">通用</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../color/index.html">
              <span>颜色</span>
              <span class="layui-font-12 layui-font-gray">Color</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../button/index.html">
              <span>按钮</span>
              <span class="layui-font-12 layui-font-gray">Button</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../icon/index.html">
              <span>图标</span>
              <span class="layui-font-12 layui-font-gray">Icon</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../anim/index.html">
              <span>动画</span>
              <span class="layui-font-12 layui-font-gray">Anim</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">表单</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/index.html">
              <span>表单组件</span>
              <span class="layui-font-12 layui-font-gray">Form</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/input.html">
              <span>输入框</span>
              <span class="layui-font-12 layui-font-gray">Input / Textarea</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/select.html">
              <span>选择框</span>
              <span class="layui-font-12 layui-font-gray">Select</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/checkbox.html">
              <span>复选框</span>
              <span class="layui-font-12 layui-font-gray">Checkbox</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/radio.html">
              <span>单选框</span>
              <span class="layui-font-12 layui-font-gray">Radio</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">展示</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../table/index.html">
              <span>表格</span>
              <span class="layui-font-12 layui-font-gray">Table</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laypage/index.html">
              <span>分页</span>
              <span class="layui-font-12 layui-font-gray">Laypage</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../treeTable/index.html">
              <span>树形表格</span>
              <span class="layui-font-12 layui-font-gray">TreeTable</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../nav/index.html">
              <span>导航菜单</span>
              <span class="layui-font-12 layui-font-gray">Nav</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../menu/index.html">
              <span>基础菜单</span>
              <span class="layui-font-12 layui-font-gray">Menu</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../tab/index.html">
              <span>选项卡</span>
              <span class="layui-font-12 layui-font-gray">Tab</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../badge/index.html">
              <span>徽章</span>
              <span class="layui-font-12 layui-font-gray">Badge</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../auxiliar/index.html">
              <span>辅助</span>
              <span class="layui-font-12 layui-font-gray">Blockquote / Fieldset / hr</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../class/index.html">
              <span>公共类</span>
              <span class="layui-font-12 layui-font-gray">Class</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../panel/index.html">
              <span>面板</span>
              <span class="layui-font-12 layui-font-gray">Panel / Card / Collapse</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../progress/index.html">
              <span>进度条</span>
              <span class="layui-font-12 layui-font-gray">Progress</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../timeline/index.html">
              <span>时间线</span>
              <span class="layui-font-12 layui-font-gray">Timeline</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../fixbar/index.html">
              <span>固定条</span>
              <span class="layui-font-12 layui-font-gray">Fixbar</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../tree/index.html">
              <span>树组件</span>
              <span class="layui-font-12 layui-font-gray">Tree</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../carousel/index.html">
              <span>轮播</span>
              <span class="layui-font-12 layui-font-gray">Carousel</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../flow/index.html">
              <span>流加载</span>
              <span class="layui-font-12 layui-font-gray">Flow</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../code/index.html">
              <span>代码预览组件</span>
              <span class="layui-font-12 layui-font-gray">Code</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">交互</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layer/index.html">
              <span>弹出层</span>
              <span class="layui-font-12 layui-font-gray">Layer</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laydate/index.html">
              <span>日期与时间选择</span>
              <span class="layui-font-12 layui-font-gray">Laydate</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../upload/index.html">
              <span>上传</span>
              <span class="layui-font-12 layui-font-gray">Upload</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../dropdown/index.html">
              <span>下拉菜单</span>
              <span class="layui-font-12 layui-font-gray">Dropdown</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../colorpicker/index.html">
              <span>颜色选择器</span>
              <span class="layui-font-12 layui-font-gray">Colorpicker</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../transfer/index.html">
              <span>穿梭框</span>
              <span class="layui-font-12 layui-font-gray">Transfer</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="index.html">
              <span>滑块</span>
              <span class="layui-font-12 layui-font-gray">Slider</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../rate/index.html">
              <span>评分</span>
              <span class="layui-font-12 layui-font-gray">Rate</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">其他</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laytpl/index.html">
              <span>模板引擎</span>
              <span class="layui-font-12 layui-font-gray">Laytpl</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../util/index.html">
              <span>工具模块</span>
              <span class="layui-font-12 layui-font-gray">Util</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    
  </ul>
</div>

  <div class="ws-content">
    <div class="layui-text ws-text" id="WS-text">
      <h1>滑块组件</h1>
<blockquote class="layui-elem-quote">
<p>滑块组件 <code>slider</code> 是一个拖拽选值的交互性组件，常与 <code>form</code> 元素结合使用。</p>
</blockquote class="layui-elem-quote">
<h2 id="examples" lay-toc="{hot: true}" style="margin-bottom: 0;">示例</h2>
<style>
.demo-slider-container .layui-code-item-preview{padding: 32px;}
.demo-slider-container .layui-code-item-preview > div{margin: 24px 0;}
</style>
<div class="demo-slider-container">
<pre class="layui-code" lay-options="{preview: true, text: {preview: '基础用法'}, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo'
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-value" class="ws-anchor ws-bold">定义初始值</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-value"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-value',
    value: 20 //初始值
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-maxmin" class="ws-anchor ws-bold">设置最大和最小值</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-maxmin"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-maxmin',
    min: 20, // 最小值
    max: 50 // 最大值
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-step" class="ws-anchor ws-bold">设置步长</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-step-1"></div>
<hr class="ws-space-16">
<div id="ID-slider-demo-step-2"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-step-1',
    step: 10 // 步长
  });
  
  slider.render({
    elem: '#ID-slider-demo-step-2',
    step: 10, // 步长
    showstep: true // 开启间隔点
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-setTips" class="ws-anchor ws-bold">设置提示文本</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-setTips-1"></div>
<hr class="ws-space-16">
<div id="ID-slider-demo-setTips-2"></div>
<div id="ID-slider-demo-setTips-result"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  var $ = layui.$;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-setTips-1',
    min: 20,
    max: 1000,
    setTips: function(value){ // 自定义提示文本
     return value + 'GB';
    }
  });
  slider.render({
    elem: '#ID-slider-demo-setTips-2',
    tips: false, // 关闭默认提示层
    change: function(value){
      $('#ID-slider-demo-setTips-result').html('当前数值：'+ value);
    }
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-input" class="ws-anchor ws-bold">开启输入框</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-input"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-input',
    input: true //输入框
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-range" class="ws-anchor ws-bold">开启范围选择</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-range-1"></div>
<hr class="ws-space-16">
<div id="ID-slider-demo-range-2"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  var layer = layui.layer;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-range-1',
    value: 40, // 初始值
    range: true, // 范围选择
    done: function(vals){
      layer.msg('开始值：'+ vals[0] + '、结尾值：'+ vals[1]);
    }
  });
  slider.render({
    elem: '#ID-slider-demo-range-2',
    value: [30, 60], // 初始值
    range: true // 范围选择
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-vertical" class="ws-anchor ws-bold">垂直滑块</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<br><br>    
<div class="layui-inline" style="margin-right: 32px;" id="ID-slider-demo-vertical-1"></div>
<div class="layui-inline" style="margin-right: 32px;" id="ID-slider-demo-vertical-2"></div>
<div class="layui-inline" style="margin-right: 32px;" id="ID-slider-demo-vertical-3"></div>
<div class="layui-inline" id="ID-slider-demo-vertical-4"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-vertical-1',
    type: 'vertical' // 垂直滑块
  });
  slider.render({
    elem: '#ID-slider-demo-vertical-2',
    value: 30,
    type: 'vertical' // 垂直滑块
  });
  slider.render({
    elem: '#ID-slider-demo-vertical-3',
    value: 50,
    range: true, // 范围选择
    type: 'vertical' // 垂直滑块
  });
  slider.render({
    elem: '#ID-slider-demo-vertical-4',
    value: 80,
    input: true, // 输入框
    type: 'vertical' // 垂直滑块
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-theme" class="ws-anchor ws-bold">自定义主题色</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-theme-1"></div>
<hr class="ws-space-16">
<div id="ID-slider-demo-theme-2"></div>
<hr class="ws-space-16">
<div id="ID-slider-demo-theme-3"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-theme-1',
    theme: '#1E9FFF' // 主题色
  });
  slider.render({
    elem: '#ID-slider-demo-theme-2',
    value: 50,
    theme: '#16b777' // 主题色
  });
  slider.render({
    elem: '#ID-slider-demo-theme-3',
    value: [30, 70],
    range: true,
    theme: '#FF5722' // 主题色
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-disabled" class="ws-anchor ws-bold">禁用滑块</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-slider-demo-disabled"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var slider = layui.slider;
  // 渲染
  slider.render({
    elem: '#ID-slider-demo-disabled',
    value: 35,
    disabled: true // 禁用滑块
  });
});
</script>
  </textarea>
</pre>
</div>
<h2 id="api" lay-toc="{}">API</h2>
<table class="layui-table">
<thead>
<tr>
<th>API</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>var slider = layui.slider</td>
<td>获得 <code>slider</code> 模块。</td>
</tr>
<tr>
<td><a href="index.html#render">var inst = slider.render(options)</a></td>
<td>slider 组件渲染，核心方法。</td>
</tr>
<tr>
<td><a href="index.html#setValue">inst.setValue(value)</a></td>
<td>设置滑块值</td>
</tr>
<tr>
<td>inst.config</td>
<td>获得当前实例的属性配置项</td>
</tr>
</tbody>
</table class="layui-table">
<h2 id="render" lay-toc="{level: 2}">渲染</h2>
<p><code>slider.render(options);</code></p>
<ul>
<li>参数 <code>options</code> : 基础属性配置项。<a href="index.html#options">#详见属性</a>
<br>注 <sup>2.8+</sup> : 除 <code>elem</code> 属性外，其他基础属性也可以直接写在元素的 <code>lay-options=&quot;{}&quot;</code> 属性中。</li>
</ul>
<pre><code class="layui-code">&lt;div id=&quot;ID-test-slider&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;class-test-slider&quot; lay-options=&quot;{value: 50}&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;class-test-slider&quot; lay-options=&quot;{value: 80}&quot;&gt;&lt;/div&gt;
 
&lt;!-- import layui --&gt;
&lt;script&gt;
layui.use(function(){
  var slider = layui.slider;
  // 单个渲染
  slider.render({
    elem: '#ID-test-slider'
  });
  // 批量渲染
  slider.render({
    elem: '.class-test-slider'
  });
});
&lt;/script&gt;
</code></pre>
<p>该方法返回一个实例对象，包含操作当前实例的相关方法成员。</p>
<pre><code class="layui-code">var inst = slider.render(options);
console.log(inst); // 得到当前实例对象
</code></pre>
<h3 id="setValue" class="ws-anchor ws-bold">设置滑块值</h3>
<p><code>inst.setValue(value, index)</code></p>
<ul>
<li>参数 <code>value</code> : 要设置的滑块数值</li>
<li>参数 <code>index</code> : 滑块所在的区间开始值或结尾值的索引，开始值：<code>0</code> ; 结尾值：<code>1</code></li>
</ul>
<pre><code class="layui-code">var slider = layui.slider;
 
// 渲染
var inst = slider.render({
  elem: '#id'
  // …
});      
 
// 设置滑块值
inst.setValue(20);
 
// 若滑块开启了范围，即： `range: true`
ins1.setValue(20, 0) // 设置开始值
ins1.setValue(60, 1) // 设置结尾值
</code></pre>
<h2 id="options" lay-toc="{level: 2, hot: true}">属性</h2>
<div>
<table class="layui-table">
  <colgroup>
    <col width="150">
    <col>
    <col width="100">
    <col width="100">
  </colgroup>
  <thead>
    <tr>
      <th>属性名</th>
      <th>描述</th>
      <th>类型</th>
      <th>默认值</th>
    </tr> 
  </thead>
  <tbody>
    <tr>
<td>elem</td>
<td>
<p>绑定元素选择器或 DOM 对象</p>
</td>
<td>string/DOM</td>
<td>-</tr>
    <tr>
<td>type</td>
<td>
<p>滑块类型，可选值有：</p>
<ul>
<li><code>default</code> 水平滑块（默认）</li>
<li><code>vertical</code>垂直滑块</li>
</ul>
</td>
<td>string</td>
<td>
<p><code>default</code></p>
</td>
    </tr>
    <tr>
<td>value</td>
<td>
<p>滑块初始值。</p>
<ul>
<li>默认可直接设置数值，如： <code>value: 50</code></li>
<li>若滑块开启 <code>range: true</code> 区间选择，则值为数组，异表示开始和结尾的区间，如： <code>value: [30, 60]</code></li>
</ul>
</td>
<td>number<br>array</td>
<td>-</td>
    </tr>
    <tr>
<td>range</td>
<td>
<p>是否开启滑块的区间选择。若开启，则滑块将出现两个可拖拽的点。</p>
</td>
<td>boolean</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
    <tr>
<td>min</td>
<td>
<p>滑块的最小值</p>
</td>
<td>number</td>
<td>
<p><code>0</code></p>
</td>
    </tr>
    <tr>
<td>max</td>
<td>
<p>滑块的最大值</p>
</td>
<td>number</td>
<td>
<p><code>100</code></p>
</td>
    </tr>
    <tr>
<td>step</td>
<td>
<p>滑块单次拖动的步长</p>
</td>
<td>number</td>
<td>
<p><code>1</code></p>
</td>
    </tr>
    <tr>
<td>showstep</td>
<td>
<p>是否显示间断点</p>
</td>
<td>boolean</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
    <tr>
<td>tips</td>
<td>
<p>鼠标移入当前圆点，是否显示当前值</p>
</td>
<td>boolean</td>
<td>
<p><code>true</code></p>
</td>
    </tr>
    <tr>
<td>input</td>
<td>
<p>是否显示滑块的数字输入框。 注：若设置 <code>range: true</code> 则该属性强制无效。</p>
</td>
<td>boolean</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
    <tr>
<td>height</td>
<td>
<p>滑动条高度。 必须设置 <code>type: 'vertical'</code> 属性，即垂直滑块时有效。</p>
</td>
<td>number</td>
<td>
<p><code>200</code></p>
</td>
    </tr>
    <tr>
<td>theme</td>
<td>
<p>滑块的主题色。</p>
</td>
<td>string</td>
<td>-</td>
    </tr>
    <tr>
<td>disabled</td>
<td>
<p>是否禁用滑块</p>
</td>
<td>boolean</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
    <tr>
<td>setTips</td>
<td colspan="3">
<p>滑块拖拽时设置提示文本的回调函数。并返回当前的 <code>value</code> 参数。用法详见：<a href="index.html#demo-setTips">#设置提示文本</a></p>
</td>
    </tr>
    <tr>
<td colspan="4" style="text-align: center"> 
<div id="options.callback" lay-pid="options" class="ws-anchor">
<p><a href="index.html#options.callback">回调函数</a></p>
</div>
</td>
    </tr>
    <tr>
<td>change</td>
<td colspan="3">
<p>滑块数值发生改变的回调函数。并返回当前的 <code>value</code> 参数。</p>
<pre><code class="layui-code">slider.render({
  elem: '#id',
  change: function(value){
    console.log(value) // 滑块当前值
    // do something
  }
});
</code></pre>
<p>一般可在该回调中将 <code>value</code> 同步给表单隐藏域，或者进行一些其它操作。</p>
</td>
    </tr>
    <tr>
<td>done <sup>2.8+</sup></td>
<td colspan="3">
<p>滑块拖拽完毕的回调函数。并返回当前的 <code>value</code> 参数。滑块拖动过程中不会触发。</p>
<pre><code class="layui-code">slider.render({
  elem: '#id',
  done: function(value){
    console.log(value) // 滑块当前值
    // do something
  }
});
</code></pre>
<p>若需将 <code>value</code> 异步发送给后端，一般采用 <code>done</code> 回调，而非 <code>change</code> 回调。</p>
</td>
    </tr>
  </tbody>
</table>
</div>
    </div>
    <div class="ws-text-tools">
      
      <a href="https://github.com/layui/layui/edit/2.x/docs/slider/index.md" rel="nofollow" target="_blank" title="在 Github 上编辑此文档">
        <i class="layui-icon layui-icon-edit"></i>
      </a>
      
    </div>
  </div>
</div>
<div class="ws-menu-bar layui-bg-green layui-hide">
  <i class="layui-icon layui-icon-spread-left"></i>
</div>
  
<div class="layui-footer ws-footer">
  <p>
    Copyright &copy; 2023 <a href="../../../index.html">Layui</a> MIT Licensed</p>
  <p id="LAY-footer-info">
    <a href="https://gitee.com/layui/layui/blob/main/DISCLAIMER.md" rel="nofollow" target="_blank">免责声明</a> 
    <a href="https://github.com/layui/layui/blob/main/LICENSE" rel="nofollow" target="_blank">开源协议</a>
    <a href="https://gitee.com/layui/" target="_blank">开源生态</a>
    <a href="https://codepen.io/layui/pen/bGxZXrd" rel="nofollow" target="_blank">在线测试</a>
    <a href="https://gitee.com/layui/layui/issues" rel="nofollow" target="_blank">社区交流</a>
  </p>
  <p>
    <span>
      鸣谢：
      <a href="https://www.upyun.com/?invite=SJ0wu6g2-&referer=layui" target="_blank" sponsor="upyun" style="color: #23A7E8;">
        <strong>又拍云</strong>
      </a>
      <a href="https://gitee.com/?referer=layui" target="_blank" sponsor="Gitee" style="color:#C71D23;">
        <strong>Gitee</strong>
      </a>
      <a href="https://www.iconfont.cn/?referer=layui" target="_blank" sponsor="Gitee" style="color: #9B16FF;">
        <strong>iconfont</strong>
      </a>
    </span>
  </p>
</div>
<div class="ws-shade"></div>
 
<script src="/public/layui/v/2.8.6/layui.js"></script>
<script>
layui.config({
  base: '//res.sentcss.com/static/dist/docs/2.8/modules/',
  version: '16',
  res: '//res.sentcss.com/static/dist/docs/',
  curl: ''
}).use('global',function(w){w.a||w.r&&w.r()});
</script>
 
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?363b2abe8678eec8a6850500ea63a63b";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</body>
</html>